package geguol.cc.widgetapplication.feature;

/**
 * 作者  格锅
 * 时间  2017/6/5 17:56
 * 文件  WidgetApplication
 * 描述
 */

public abstract class PriorityRunnable implements Runnable, Comparable<PriorityRunnable> {
	private int priority;

	public PriorityRunnable(int priority) {
		if (priority < 0)
			throw new IllegalArgumentException();
		this.priority = priority;
	}

	// 负 当前的优先级小| 正 当前的大|0 相同

	@Override
	public int compareTo(PriorityRunnable another) {
		int my = this.getPriority();
		int other = another.getPriority();
		return my < other ? 1 : my > other ? -1 : 0;
	}

	@Override
	public void run() {
		doSth();
	}

	public abstract void doSth();

	public int getPriority() {
		return priority;
	}
}
